<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
   
    const Child1 = {
      template: `
        <div>
          child1组件  
          <button @click="emit">向兄弟组件通信</button>
        </div>
      `,
      data(){
        return {
          msg:'我是子组件1中的数据'
        }
      },
      methods: {
        emit(){
          alert('子组件方法调用了')
        }
      },
      mounted() {
        console.log(this.$parent)
      },
    } 

  
    const Home = {
      template: `
        <div>
          home组件
          <hr/>
          <child1></child1>
         
        </div>
      `,
      data(){
        return {
          msg:'父组件数据'
        }
      },
      mounted() {
        // 当当前组件的template 编译真实dom时触发
        console.log(this.$children)
      },
      components:{
        Child1
      }
    }
    Vue.component('Home', Home);
    const vm = new Vue({
      el: '#app'
    })


   /*  function fn(){
      console.log(this);
    }
    var fn2 = fn.bind(3);
    fn2() */
  </script>
</body>
</html>